// 罗马数字转阿拉伯数字

function romanToInt(s) {
    let map = {
        'I': 1,
        'V': 5,
        'X': 10,
        'L': 50,
        'C': 100,
        'D': 500,
        'M': 1000
    }
    let result = 0;
    let max = 0;
    let len = s.length;

    while(len--) {
        let char = s[len];
        let num = map[char];
        if(max > num) {
            result -= num;
            continue;
        }
        max = num;
        result += num;
    }
console.log(result);
    return result;
}


romanToInt('DM');